<template>
<!-- xinzeng -->
    <div class="icon">
        <swiper :options="swiperOption" >
          <swiper-slide v-for="(page, index) of pages" :key="index">
            <div class="icon-box" v-for="item of page" :key="item.id">
                <div class="icon-imgs">
                    <img class="icon-img-content" :src="item.urlImg" alt="">
                </div>
                <p class="icon-text" v-text="item.desc"></p>
            </div>
          </swiper-slide>
          <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'Icon',
  props: {
    iconlist: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false,
        pagination: '.swiper-pagination',
        paginationClickable: true // 那三个小点点
      }
    }
  },
  //   data () {
  //     return {
  //   IconList: [{
  //     id: '0001',
  //     Urlimg: require('@/assets/styles/images/icon1.png'),
  //     desc: '酒店'
  //   }, {
  //     id: '0002',
  //     Urlimg: require('@/assets/styles/images/icon2.png'),
  //     desc: '机票'
  //   }, {
  //     id: '0003',
  //     Urlimg: require('@/assets/styles/images/icon3.png'),
  //     desc: '火车票'
  //   }, {
  //     id: '0004',
  //     Urlimg: require('@/assets/styles/images/icon4.png'),
  //     desc: '度假'
  //   }, {
  //     id: '0005',
  //     Urlimg: require('@/assets/styles/images/icon6.png'),
  //     desc: '海外酒店'
  //   }, {
  //     id: '0006',
  //     Urlimg: require('@/assets/styles/images/icon7.png'),
  //     desc: '低价机票'
  //   }, {
  //     id: '0007',
  //     Urlimg: require('@/assets/styles/images/icon8.png'),
  //     desc: '汽车票船票'
  //   }, {
  //     id: '0008',
  //     Urlimg: require('@/assets/styles/images/icon9.png'),
  //     desc: '自由行'
  //   }, {
  //     id: '0009',
  //     Urlimg: require('@/assets/styles/images/icon6.png'),
  //     desc: '景点门票'
  //   }, {
  //     id: '0010',
  //     Urlimg: require('@/assets/styles/images/icon10.png'),
  //     desc: '攻略'
  //   }]
  //     }
  //   },
  computed: {
    pages () {
      const pages = []
      this.iconlist.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped>
.icon >>> .swiper-container{
  width: 100%;
  overflow: hidden;
  height: 0;
  padding-bottom: 64%;
}
.swiper-slide{
    margin-left: 8px;
}
 .swiper-container-horizontal > .swiper-pagination-bullets {
    bottom: 4px;
}
.icon-box{
    position: relative;
    overflow: hidden;
    height: 0;
    width: 25%;
    float: left;
    padding-bottom: 24%;
    margin-bottom: 20px;
}
.icon-imgs{
    position: absolute;
    top: 2px;
    left: 0;
    right: 0;
    bottom: 1.1rem;
}
.icon-img-content{
    display: block;
    height: 97%;
    margin: 0px auto;
}
.icon-text{
    text-align: center;
    color: #333;
    position: absolute;
    bottom: -1.3rem;
    left: 0;
    right: 0;
    height: 1.3rem;
    line-height: 1.3rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.icon >>> .swiper-pagination-bullet-active {
    background: rgb(4, 170, 148,.6);
}
.icon >>> .swiper-pagination-bullet {
    width: 8px;
    border-radius: 4px;
}
</style>
